HiSEN

Could not initialize class io.jsonwebtoken.impl.DefaultJwtBuilder

使用jsonwebtoken出现如下错误

1
2
3
Could not initialize class io.jsonwebtoken.impl.DefaultJwtBuilder
java.lang.NoClassDefFoundError: Could not initialize class io.jsonwebtoken.impl.DefaultJwtBuilder
at io.jsonwebtoken.Jwts.builder(Jwts.java:116) ~[jjwt-0.7.0.jar:0.7.0]

原因,因为jackson-databindb版本冲突,直接去掉了依赖

jwt必须依赖Jackson所以报错了

出错时候的配置

1
2
3
4
5
6
7
8
9
10
11
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.7.0</version>
<exclusions>
<exclusion>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
</exclusions>
</dependency>

解决办法

1
2
3
4
5
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.7.0</version>
</dependency>